package com.bosssoft.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bosssoft.entity.dto.FibConferenceBudgetDTO;
import com.bosssoft.entity.po.FibConferenceBudgetPO;
import com.bosssoft.entity.vo.FibConferenceBudgetVO;
import com.bosssoft.entity.vo.FibTrainBudgetVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bosssoft.mapper.FibConferenceBudgetMapper;
import com.bosssoft.service.FibConferenceBudgetService;

import javax.annotation.Resource;

/**
 * @author Li kexi
 * Created on 2021/8/19.15:46
 */
@Service
@Slf4j
public class FibConferenceBudgetServiceImpl extends ServiceImpl<FibConferenceBudgetMapper, FibConferenceBudgetPO> implements FibConferenceBudgetService {

    @Resource
    private FibConferenceBudgetMapper fibConferenceBudgetMapper;

    @Override
    public int updateBatch(List<FibConferenceBudgetPO> list) {
        return baseMapper.updateBatch(list);
    }

    @Override
    public int updateBatchSelective(List<FibConferenceBudgetPO> list) {
        return baseMapper.updateBatchSelective(list);
    }

    @Override
    public int batchInsert(List<FibConferenceBudgetPO> list) {
        return baseMapper.batchInsert(list);
    }

    @Override
    public int insertOrUpdate(FibConferenceBudgetPO record) {
        return baseMapper.insertOrUpdate(record);
    }

    @Override
    public int insertOrUpdateSelective(FibConferenceBudgetPO record) {
        return baseMapper.insertOrUpdateSelective(record);
    }

    @Override
    public boolean addConference(FibConferenceBudgetDTO fibConferenceBudgetDTO) {
        FibConferenceBudgetPO fibConferenceBudgetPO = new FibConferenceBudgetPO();
        BeanUtils.copyProperties(fibConferenceBudgetDTO, fibConferenceBudgetPO);

        //todo:创建人从前端接收还是从后端查询呢

        boolean save = save(fibConferenceBudgetPO);
        return save;
    }

    @Override
    public boolean editConference(FibConferenceBudgetDTO fibConferenceBudgetDTO) {

        FibConferenceBudgetPO fibConferenceBudgetPO = new FibConferenceBudgetPO();
        BeanUtils.copyProperties(fibConferenceBudgetDTO, fibConferenceBudgetPO);
        FibConferenceBudgetPO byId = getById(fibConferenceBudgetPO.getId());
        if (byId == null) {
            log.info("");
            //todo:异常处理
            return false;
        }
        //todo:修改人的获取方式待定
        boolean b = updateById(fibConferenceBudgetPO);
        return b;
    }

    @Override
    public Page<FibConferenceBudgetVO> selectConference(FibConferenceBudgetVO fibConferenceBudgetVO, Integer current, Integer size) {

        Page<FibConferenceBudgetPO> page = new Page<>(current, size);
        QueryWrapper<FibConferenceBudgetPO> queryWrapper = new QueryWrapper<>();
        if (ObjectUtil.isNotNull(fibConferenceBudgetVO.getId())) {
            queryWrapper.like("id", fibConferenceBudgetVO.getId());
        }
        Page<FibConferenceBudgetPO> poPage = fibConferenceBudgetMapper.selectPage(page, queryWrapper);
        Page<FibConferenceBudgetVO> voPage = new Page<>(current, size);
        BeanUtils.copyProperties(poPage, voPage);
        return voPage;
    }

}
